<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>跟进新客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css">
    <!--<link rel="stylesheet" href="css/layuimini.css">-->
    <link rel="stylesheet" href="css/public.css" media="all">
</head>
<body>
<div class="layuimini-container ">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <form id="searchList" class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">客户ID</label>
                        <div class="layui-input-inline">
                            <input type="text" id="custId" name="custId" autocomplete="off" class="layui-input"
                                   onkeyup="this.value=this.value.replace(/[, ]/g,'')">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="startTime" id="=startTime" class="layui-input datetime">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">终止时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="endTime" id="endTime" class="layui-input datetime">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i
                                class="layui-icon"></i> 搜 索</a>
                    </div>

                </div>
            </form>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!--<button class="layui-btn layui-btn-sm data-add-btn" > 添加跟进客户 </button>-->
                <a href="javascript:;" class="layui-btn layui-btn-sm" data-iframe-tab="following.html"
                   data-title="添加跟进" data-icon="fa fa-gears">
                    <i class="layui-icon ">&#xe624;</i>添加跟进记录</a>
                <!--<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"> 删除客户 </button>-->
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
    </div>

</div>
<script src="lib/layui-v2.5.5/layui.all.js" charset="utf-8"></script>
<!--tab跳转需要layuimini-->
<script src="js/lay-module/layuimini/layuimini.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'laydate', 'util'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            util = layui.util,
            laydate = layui.laydate,
            layuimini = layui.layuimini;
        $('.datetime').each(function () {
            laydate.render({
                elem: this       //使用this指向当前元素,不能使用class名, 否则只有第一个有效
                , type: 'datetime'
            });
        });
        <!--表格-->
        var tableIns = table.render({
            elem: '#currentTableId',
            url: 'followRecordList',
            method: 'post',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLETIPS',
                icon: 'layui-icon-tips'
            }],
            request: {
                pageName: 'page', //页码的参数名称，默认：pageNum
                limitName: 'pageSize' //每页数据量的参数名，默认：pageSize
            },
            parseData: function (res) { //res 即为原始返回的数据
                //res.code=0;
                console.log(res);
                return {
                    "code": 0, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.rows //解析数据列表
                };
            },
            cols: [
                [
                    {field: 'id', width: 100, title: 'ID', sort: true},
                    {field: 'custId', width: 100, title: '客户ID', sort: true},
                    {field: 'userId', width: 150, title: '负责人ID'},
                    {field: 'way', width: 150, title: '跟进方式'},
                    {field: 'record', width: 150, title: '跟进信息'},
                    {field: 'remark', title: '备注', width: 150},
                    {field: 'recordTime', width: 160, title: '记录时间',templet : "<div>{{layui.util.toDateString(d.recordTime, 'yyyy-MM-dd HH:mm')}}</div>", sort: true},
                    {title: '操作', minWidth: 50, templet: '#currentTableBar', align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            var text = JSON.parse(result);
            table.reload('currentTableId', {
                method: 'post'
                , where: {  //text  //搜索框里的各个参数,通过这个实现搜索功能，table同一数据接口
                    "custId": text.custId,
                    "startTime": text.startTime,
                    "endTime": text.endTime
                }
                , page: {
                    curr: 1
                }
            });
            layer.msg("数据正在加载", {icon: 6, time: 1000});
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑跟进记录',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    resize: false,
                    shadeClose: true,
                    area: ['60%', '70%'],
                    content: 'followRecordEdit.html?edit=1&id=' + data.id
                });
                /* $(window).on("resize", function () {
                     layer.full(index);
                 });*/
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确定要删除该记录吗？', function (x) {
                    $.ajax({
                        type: "post",
                        data: {"id": data.id},
                        url: "deleteRecord",
                        success: function (data) {
                            //layer.alert();
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                layer.close(index);
                                table.reload('currentTableId', {});
                            });

                        }
                    });
                    layer.close(x);
                });
            }
        })
    });
</script>
</body>
</html>
